package com.mycompany.project.client.chee;

import com.google.gwt.user.client.ui.Image;
import com.mycompany.project.client.ModuleType;

/**
 * This class will used to provide information about modules.
 *
 * @author LeeNou, Timothy Duch
 *
 */
public class Module extends Image {
    /**
     * Image location for the medical.
     */
    private static final int MEDICALIMAGE = 9;
    /**
     * Image location for the airlock.
     */
    private static final int AIRLOCKIMAGE = 8;

    /**
     * Image location for the gym.
     */
    private static final int GYMIMAGELOCALE = 7;
    /**
     * Image location for the sanitation.
     */
    private static final int SANITATION = 6;
    /**
     * Image location for the canteen.
     */
    private static final int CANTEEN = 5;
    /**
     * Image location for the dormitory.
     */
    private static final int DORMITORY = 4;
    /**
     * Image location for the food.
     */
    private static final int FOODIMAGE = 3;
    /**
     * Image location for the power.
     */
    private static final int POWERIMAGE = 2;
    /**
     * Image location for the control.
     */
    private static final int CONTROLIMAGE = 1;
    /**
     * Image location for the plain.
     */
    private static final int PLAINIMAGELOCALE = 0;

    /**
     * Initializes the images of the modules.
     */
    /**
     * The string length of MODULEIMAGE and MODULEFILL.
     */
    private static final int STRINGLENGTH = 10;
    /**
     * Container for MODULEIMAGE.
     */
    private static final String[] MODULEIMAGE = new String[STRINGLENGTH];
    /**
     * Container for MODULEFILL.
     */
    private static final String[] MODULEFILL = new String[STRINGLENGTH];
    /**
     * Max number of modules.
     */
    public static final int MAX_SIZE = 10;
    /**
     * The module type.
     */
    private  ModuleType moduleType;

    /**
     * The code number.
     */
    private int codeNumber;
    /**
     * The x position.
     */
    private transient int positionx;
    /**
     * The y position.
     */
    private transient int positiony;
    /**
     * The stats of the module.
     */
    private String stats;
    /**
     * The orientation of the module.
     */
    private int orientation;
    /**
     * Configuration map x coordinate.
     */
    private transient int gridx = -1;
    /**
     * Configuration map y coordinate.
     */
    private transient int gridy = -1;

    /**
     * Setter for the module type.
     * @param type is the module type.
     */
    public final void setModuleType(final ModuleType type) {
         moduleType = type;
    }
    /**
     * Initializes images.
     */
    public static void initImages() {
        MODULEIMAGE[AIRLOCKIMAGE] = "images/Airlock.jpg";
        MODULEFILL[AIRLOCKIMAGE] = "images/Airfill.jpg";
        MODULEIMAGE[CONTROLIMAGE] = "images/Control.jpg";
        MODULEFILL[CONTROLIMAGE] = "images/Controlfill.jpg";
        MODULEIMAGE[POWERIMAGE] = "images/Power.jpg";
        MODULEFILL[POWERIMAGE] = "images/Powerfill.jpg";
        MODULEIMAGE[FOODIMAGE] = "images/Food & Water storage.jpg";
        MODULEFILL[FOODIMAGE] = "images/FWfill.jpg";
        MODULEIMAGE[DORMITORY] = "images/Dormitory.jpg";
        MODULEFILL[DORMITORY] = "images/Dormfill.jpg";
        MODULEIMAGE[CANTEEN] = "images/Canteen.jpg";
        MODULEFILL[CANTEEN] = "images/Canteenfill.jpg";
        MODULEIMAGE[SANITATION] = "images/Sanitation.jpg";
        MODULEFILL[SANITATION] = "images/Sanitationfill.jpg";
        MODULEIMAGE[GYMIMAGELOCALE] = "images/Gym & Relaxation.jpg";
        MODULEFILL[GYMIMAGELOCALE] = "images/GymRelaxfill.jpg";
        MODULEIMAGE[PLAINIMAGELOCALE] = "images/Plain.jpg";
        MODULEFILL[PLAINIMAGELOCALE] = "images/Plainfill.jpg";
        MODULEIMAGE[MEDICALIMAGE] = "images/Medical.jpg";
        MODULEFILL[MEDICALIMAGE] = "images/Medicalfill.jpg";
    }

    /**
     *
     * @param number
     *            checks number
     * @return the module type associated with number
     */
    public static ModuleType checkModuleType(final int number) {
        ModuleType temp;
        if (number == ModuleType.AIR_LOCK.ordinal()) {
            temp = ModuleType.AIR_LOCK;
        } else if (number == ModuleType.CANTEEN.ordinal()) {
            temp =  ModuleType.CANTEEN;
        } else if (number == ModuleType.CONTROL.ordinal()) {
            temp =  ModuleType.CONTROL;
        } else if (number == ModuleType.DORMITORY.ordinal()) {
            temp =  ModuleType.DORMITORY;
        } else if (number == ModuleType.FOOD_WATER_STORAGE.ordinal()) {
            temp =  ModuleType.FOOD_WATER_STORAGE;
        } else if (number == ModuleType.GYM_RELAXATION.ordinal()) {
            temp =  ModuleType.GYM_RELAXATION;
        } else if (number == ModuleType.MEDICAL.ordinal()) {
            temp =  ModuleType.MEDICAL;
        } else if (number == ModuleType.PLAIN.ordinal()) {
            temp =  ModuleType.PLAIN;
        } else if (number == ModuleType.POWER.ordinal()) {
            temp =  ModuleType.POWER;
        } else {
            temp =  ModuleType.SANITATION;
        }
        return temp;
    }

    /**
     * Gets the string containing data about the module.
     * @return the string containing data about this module
     */
    public final String getString() {
        String moduleInformation = "";
        moduleInformation = "Module Type:"
                            + moduleType.toString().toLowerCase() + "\n";
        moduleInformation += "Module Code#:" + codeNumber + "\n";
        moduleInformation += "Module Status:" + stats + "\n";
        moduleInformation += "Module Orientation:" + orientation + "\n";
        moduleInformation += "Live Map @ (" + positionx + "," + positiony + ")\n"
        				+ "Configuration Map@ (" + this.gridy + "," + this.gridx+")";
        return moduleInformation;
    }

    /**
     * Getter for the MODULEIMAGE.
     * @param index is the index of the image.
     * @return the image content.
     */
    public static String getModuleImage(final int index) {
        return MODULEIMAGE[index];
    }

    /**
     * Getter for the MODULEFILL.
     * @param index is the index of the image.
     * @return the image content.
     */
    public static String getModuleFill(final int index) {
        return MODULEFILL[index];
    }

    /**
     * Getter for the moduleType.
     * @return the module type.
     */
    public final ModuleType getModuleType() {
        return moduleType;
    }

    /**
     * Getter for the x position.
     * @return the x position.
     */
    public final int getPositionX() {
        return positionx;
    }

    /**
     * Getter for the y position.
     * @return the y position.
     */
    public final int getPositionY() {
        return positiony;
    }

    /**
     * Getter for the stats.
     * @return the stats.
     */
    public final String getStats() {
        return stats;
    }

    /**
     * Getter for the orientation.
     * @return the orientation.
     */
    public final int getOrientation() {
        return orientation;
    }

    /**
     * Getter for the code number.
     * @return the code number.
     */
    public final int getCodeNumber() {
        return codeNumber;
    }

    /**
     * Setter for the x position.
     * @param xposition is the new x position.
     */
    public final void setPositionX(final int xposition) {
        this.positionx = xposition;
    }

    /**
     * Setter for the y position.
     * @param yposition is the new y position.
     */
    public final void setPositionY(final int yposition) {
        this.positiony = yposition;
    }

    /**
     * Setter for the orientation.
     * @param orient is the new orientation.
     */
    public final void setOrientation(final int orient) {
        this.orientation = orient;
    }

    /**
     * Setter for the stats.
     * @param stat is the new stats for the class.
     */
    public final void setStats(final String stat) {
        this.stats = stat;
    }

    /**
     * Setter for the code number.
     * @param code is the new codeNumber.
     */
    public final void setCodeNumber(final int code) {
        this.codeNumber = code;
    }

    /**
     * Setter for the gridx.
     * @param xgrid is the new gridx.
     */
    public final void setGridX(final int xgrid) {
        this.gridx = xgrid;
    }

    /**
     * Setter for the gridy.
     * @param ygrid is the new gridy.
     */
    public final void setGridY(final int ygrid) {
        this.gridy = ygrid;
    }

    /**
     * Getter for the gridx.
     * @return the gridx.
     */
    public final int getGridX() {
        return gridx;
    }

    /**
     * Getter for the gridy.
     * @return the gridy.
     */
    public final int getGridY() {
        return gridy;
    }

}
